import java.util.ArrayList;
import java.util.List;

class Solution {
    //组合
    public List<List<Integer>> ret;
    public List<Integer> path;
    public int n;
    public int k;
    public List<List<Integer>> combine(int nn, int kk) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        n = nn;
        k = kk;
        dfs(1);
        return ret;
    }
    public void dfs(int index){
        //递归出口
        if(path.size() == k){
            ret.add(new ArrayList<>(path));
            return;
        }

        //函数体
        for(int i = index; i <= n; i++){
            path.add(i);
            dfs(i + 1);//递归
            path.remove(path.size() - 1);//回溯
        }
    }
}